﻿// -----------------------------------------------------------------------
// Copyright (c) Microsoft Corporation.  All rights reserved.
// -----------------------------------------------------------------------
using System;
using System.Reflection;
using System.UnitTesting;

namespace System.IO 
{
    public static class FileIO
    {
        private static string _temporaryDirectory;

        public static string GetTemporaryDirectory()
        {
            if (_temporaryDirectory == null)
            {
                string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

                path = Path.Combine(path, "TestRunTempDirectory");

                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }

                _temporaryDirectory = path;
            }

            return _temporaryDirectory;
        }

        public static string GetTemporaryFileName(string extension)
        {
            return Path.Combine(GetTemporaryDirectory(), TestServices.GenerateRandomString() + "." + extension);
        }
    }
}